package com.atguigu.sparktuning.cache_01

import com.atguigu.sparktuning.bean.CoursePay
import com.atguigu.sparktuning.utils.InitUtil
import org.apache.spark.SparkConf
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.{Row, SparkSession}
import org.apache.spark.storage.StorageLevel

/**
  * @Author  Zhongxu.Zhao
  * @ClassName RddCacheKryoDemo
  * @Date 2021/12/13 23:47
  * @Desc: TODO
 **/
object RddCacheKryoDemo {
  def main(args: Array[String]): Unit = {
    val sparkconf: SparkConf = new SparkConf().setAppName(this.getClass.getSimpleName).setMaster("local").set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
      .registerKryoClasses(Array(classOf[CoursePay]))
    val spark: SparkSession = InitUtil.initSparkSession(sparkconf)
    import spark.implicits._

    val result: RDD[Row] = spark.sql("select * from sparktuning.course_pay").rdd
    result.persist(StorageLevel.MEMORY_ONLY_SER)
    result.foreachPartition((p:Iterator[Row]) =>(p.foreach(item => println(item.getInt(3)))))
    while(true ) {

    }
  }

}
